package cst.a931xmc.yuejian20.Activity;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;

import java.util.List;

import cst.a931xmc.yuejian20.Adapter.ShowAdapter;
import cst.a931xmc.yuejian20.Bean.ShowBean;
import cst.a931xmc.yuejian20.Listener.Listener;
import cst.a931xmc.yuejian20.Model.ShowModel;
import cst.a931xmc.yuejian20.R;

public class MyShowActivity extends AppCompatActivity implements View.OnClickListener {
    private ImageButton btn_back;
    private RecyclerView recyclerView;
    private ShowAdapter adapter;
    private int user_id;
    private ShowModel model;
    private Listener<List<ShowBean>> listener;
    SharedPreferences sp;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_myshow);
        init();
        initViews();
    }

    public void init(){
        btn_back = findViewById(R.id.btn_back);
        btn_back.setOnClickListener(this);
        sp = getSharedPreferences("user_id", Context.MODE_PRIVATE);
        user_id = sp.getInt("user_id",0);
    }

    public void initViews(){
        recyclerView = findViewById(R.id.rv_myshow);
        recyclerView.setLayoutManager(new LinearLayoutManager(MyShowActivity.this));
        adapter = new ShowAdapter(MyShowActivity.this);
        listener = new Listener<List<ShowBean>>() {
            @Override
            public void onResponse(List<ShowBean> list) {
                recyclerView.setAdapter(adapter);
                adapter.setList(list);
            }

            @Override
            public void onFail(String message) {

            }
        };
        model = new ShowModel();
        model.getMyShowList(user_id,listener);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_back:
                finish();
                break;
        }
    }
}
